package com.hzhr.iot.device.convertor;

import com.hzhr.iot.device.convertor.custom.*;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import java.util.Map;
import com.hzhr.iot.device.model.alarmData.AlarmDataModel;
import com.hzhr.iot.device.model.alarmData.AlarmDataPostModel;
import com.hzhr.iot.device.entity.AlarmDataEntity;
import com.hzhr.iot.device.entity.ext.AlarmDataEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.hzhr.iot.device.model.alarmData.AlarmDataModel;
import com.hzhr.iot.device.model.alarmData.AlarmDataGetModel;
import com.hzhr.iot.device.model.alarmData.AlarmDataPostModel;
import com.hzhr.iot.device.queryModel.custom.AlarmDataCustomQueryModel;

@Component
public class AlarmDataConvertor {
    @Autowired
    CollectDataCustomConvertor collectDataCustomConvertor;
    @Autowired
    CollectDeviceCustomConvertor collectDeviceCustomConvertor;
    @Autowired
    CollectDeviceTypeCustomConvertor collectDeviceTypeCustomConvertor;
    @Autowired
    DeviceInfoCardCustomConvertor deviceInfoCardCustomConvertor;
    @Autowired
    DeviceMaintenanceCardCustomConvertor deviceMaintenanceCardCustomConvertor;
    @Autowired
    DeviceMaintenanceCardItemCustomConvertor deviceMaintenanceCardItemCustomConvertor;
    @Autowired
    ImplFactoryCustomConvertor implFactoryCustomConvertor;
    @Autowired
    ImplIotDeviceTypeCustomConvertor implIotDeviceTypeCustomConvertor;
    @Autowired
    ImplRecordCustomConvertor implRecordCustomConvertor;
    @Autowired
    IotDeviceCustomConvertor iotDeviceCustomConvertor;
    @Autowired
    IotDeviceTypeCustomConvertor iotDeviceTypeCustomConvertor;
    @Autowired
    OptionsCustomConvertor optionsCustomConvertor;
    @Autowired
    ProdFactoryCustomConvertor prodFactoryCustomConvertor;
    @Autowired
    RegulatorCollectDataCustomConvertor regulatorCollectDataCustomConvertor;
    @Autowired
    UserCompanyCustomConvertor userCompanyCustomConvertor;

    public AlarmDataEntity alarmDataModel2entity(AlarmDataModel in) {
        //未转换字段: createTime isValid outId updateTime state 
        if (in == null) return null;
        AlarmDataEntity result = new AlarmDataEntity();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setGasUserId(HzhrTypeUtil.integer2integer(in.getGasUserId()));
        result.setCurrentTm(HzhrTypeUtil.long2date(in.getCurrentTm()));
        result.setAlarmType(HzhrTypeUtil.string2string(in.getAlarmType()));
        return result;
    }
    public AlarmDataEntity alarmDataModel2entity(AlarmDataModel in, AlarmDataEntity ori) {
        //未转换字段: createTime isValid outId updateTime state 
        if (in == null) return null;
        AlarmDataEntity result = ori;

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setGasUserId(HzhrTypeUtil.integer2integer(in.getGasUserId()));
        result.setCurrentTm(HzhrTypeUtil.long2date(in.getCurrentTm()));
        result.setAlarmType(HzhrTypeUtil.string2string(in.getAlarmType()));
        return result;
    }
    public List<AlarmDataEntity> alarmDataModelList2entityList(List<AlarmDataModel> in) {
        if (in == null) return null;
        List<AlarmDataEntity> result = new ArrayList<>();
        for (AlarmDataModel item : in) {
            result.add(alarmDataModel2entity(item));
        }
        return result;
    }
    public AlarmDataModel entity2alarmDataModel(AlarmDataEntity in) {
        //未转换字段: alarmTypeDes 
        if (in == null) return null;
        AlarmDataModel result = new AlarmDataModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setGasUserId(HzhrTypeUtil.integer2integer(in.getGasUserId()));
        result.setCurrentTm(HzhrTypeUtil.date2long(in.getCurrentTm()));
        result.setAlarmType(HzhrTypeUtil.string2string(in.getAlarmType()));
        return result;
    }
    public List<AlarmDataModel> entityList2alarmDataModelList(List<AlarmDataEntity> in) {
        if (in == null) return null;
        List<AlarmDataModel> result = new ArrayList<>();
        for (AlarmDataEntity item : in) {
            result.add(entity2alarmDataModel(item));
        }
        return result;
    }
    public AlarmDataModel ext2alarmDataModel(AlarmDataEntityExt in) {
        //未转换字段: alarmTypeDes 
        if (in == null) return null;
        AlarmDataModel result = new AlarmDataModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setGasUserId(HzhrTypeUtil.integer2integer(in.getGasUserId()));
        result.setCurrentTm(HzhrTypeUtil.date2long(in.getCurrentTm()));
        result.setAlarmType(HzhrTypeUtil.string2string(in.getAlarmType()));
        return result;
    }
    public List<AlarmDataModel> extList2alarmDataModelList(List<AlarmDataEntityExt> in) {
        if (in == null) return null;
        List<AlarmDataModel> result = new ArrayList<>();
        for (AlarmDataEntityExt item : in) {
            result.add(ext2alarmDataModel(item));
        }
        return result;
    }
    public AlarmDataGetModel extList2alarmDataGetModel(List<AlarmDataEntityExt> extList, Integer total, Integer changeCount, Map<String, Object> query) {
        List<AlarmDataModel> modelList = extList2alarmDataModelList(extList);
        if (modelList == null) {
            AlarmDataGetModel result = new AlarmDataGetModel();
            result.setTotal(total);
            result.setChangeCount(changeCount);
            return result;
        }

         String _show = HzhrTypeUtil.object2string(query.get("_show"));
         Boolean _show_info = query.get("_show_info") != null ? Boolean.parseBoolean(query.get("_show_info").toString()) : false;

        if (!_show_info) {
            for (AlarmDataModel model : modelList) {
                model.setCollectDeviceId(null);
                model.setIotDeviceId(null);
                model.setGasUserId(null);
                model.setCurrentTm(null);
                model.setAlarmType(null);
                model.setAlarmTypeDes(null);
            }
        }

        AlarmDataGetModel result = new AlarmDataGetModel();
        if ("one".equals(_show)) {
            if (modelList.size() > 0) {
                result.setModel(modelList.get(0));
            }
         }
        if ("list".equals(_show)) {
            result.setModelList(modelList);
        }
        result.setTotal(total);
        result.setChangeCount(changeCount);
        return result;
    }
    public AlarmDataGetModel entity2alarmDataGetModel(AlarmDataEntity entity, Integer total, Integer changeCount, Map<String, Object> query) {
        List<AlarmDataEntityExt> extList = new ArrayList<>();
        if (entity == null) return extList2alarmDataGetModel(extList, total, changeCount, query);
        extList.add(HzhrJsonUtil.convertObjectType(entity, AlarmDataEntityExt.class));
        return extList2alarmDataGetModel(extList, total, changeCount, query);
     }
    public AlarmDataEntity alarmDataPostModel2entity(AlarmDataPostModel in) {
        //未转换字段: createTime isValid outId updateTime id state 
        if (in == null) return null;
        AlarmDataEntity result = new AlarmDataEntity();

        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setGasUserId(HzhrTypeUtil.integer2integer(in.getGasUserId()));
        result.setCurrentTm(HzhrTypeUtil.long2date(in.getCurrentTm()));
        result.setAlarmType(HzhrTypeUtil.string2string(in.getAlarmType()));
        return result;
    }
    public AlarmDataEntity alarmDataPostModel2entity(AlarmDataPostModel in, AlarmDataEntity ori) {
        //未转换字段: createTime isValid outId updateTime id state 
        if (in == null) return null;
        AlarmDataEntity result = ori;

        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setGasUserId(HzhrTypeUtil.integer2integer(in.getGasUserId()));
        result.setCurrentTm(HzhrTypeUtil.long2date(in.getCurrentTm()));
        result.setAlarmType(HzhrTypeUtil.string2string(in.getAlarmType()));
        return result;
    }
    public List<AlarmDataEntity> alarmDataPostModelList2entityList(List<AlarmDataPostModel> in) {
        if (in == null) return null;
        List<AlarmDataEntity> result = new ArrayList<>();
        for (AlarmDataPostModel item : in) {
            result.add(alarmDataPostModel2entity(item));
        }
        return result;
    }
    public AlarmDataPostModel entity2alarmDataPostModel(AlarmDataEntity in) {
        //未转换字段: 
        if (in == null) return null;
        AlarmDataPostModel result = new AlarmDataPostModel();

        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setGasUserId(HzhrTypeUtil.integer2integer(in.getGasUserId()));
        result.setCurrentTm(HzhrTypeUtil.date2long(in.getCurrentTm()));
        result.setAlarmType(HzhrTypeUtil.string2string(in.getAlarmType()));
        return result;
    }
    public List<AlarmDataPostModel> entityList2alarmDataPostModelList(List<AlarmDataEntity> in) {
        if (in == null) return null;
        List<AlarmDataPostModel> result = new ArrayList<>();
        for (AlarmDataEntity item : in) {
            result.add(entity2alarmDataPostModel(item));
        }
        return result;
    }
    public AlarmDataPostModel ext2alarmDataPostModel(AlarmDataEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        AlarmDataPostModel result = new AlarmDataPostModel();

        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setGasUserId(HzhrTypeUtil.integer2integer(in.getGasUserId()));
        result.setCurrentTm(HzhrTypeUtil.date2long(in.getCurrentTm()));
        result.setAlarmType(HzhrTypeUtil.string2string(in.getAlarmType()));
        return result;
    }
    public List<AlarmDataPostModel> extList2alarmDataPostModelList(List<AlarmDataEntityExt> in) {
        if (in == null) return null;
        List<AlarmDataPostModel> result = new ArrayList<>();
        for (AlarmDataEntityExt item : in) {
            result.add(ext2alarmDataPostModel(item));
        }
        return result;
    }
    public AlarmDataCustomQueryModel alarmDataService_query2queryModel(Map<String, Object> query) {
        AlarmDataCustomQueryModel queryModel = new AlarmDataCustomQueryModel();

        Integer _equal_id = HzhrTypeUtil.object2integer(query.get("_equal_id"));
        if (_equal_id != null) {
            queryModel.setEqual_id(_equal_id);
         }

        Integer _equal_collectDeviceId = HzhrTypeUtil.object2integer(query.get("_equal_collectDeviceId"));
        if (_equal_collectDeviceId != null) {
            queryModel.setEqual_collectDeviceId(_equal_collectDeviceId);
         }

        Integer _equal_iotDeviceId = HzhrTypeUtil.object2integer(query.get("_equal_iotDeviceId"));
        if (_equal_iotDeviceId != null) {
            queryModel.setEqual_iotDeviceId(_equal_iotDeviceId);
         }

        Integer _equal_gasUserId = HzhrTypeUtil.object2integer(query.get("_equal_gasUserId"));
        if (_equal_gasUserId != null) {
            queryModel.setEqual_gasUserId(_equal_gasUserId);
         }

        Date _equal_currentTm = HzhrTypeUtil.object2date(query.get("_equal_currentTm"));
        if (_equal_currentTm != null) {
            queryModel.setEqual_currentTm(_equal_currentTm);
         }

        Date _greaterthanorequal_currentTm = HzhrTypeUtil.object2date(query.get("_greaterthanorequal_currentTm"));
        if (_greaterthanorequal_currentTm != null) {
            queryModel.setGreaterthanorequal_currentTm(_greaterthanorequal_currentTm);
         }

        Date _lessthan_currentTm = HzhrTypeUtil.object2date(query.get("_lessthan_currentTm"));
        if (_lessthan_currentTm != null) {
            queryModel.setLessthan_currentTm(_lessthan_currentTm);
         }

        Boolean _show_info = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (_show_info != null && _show_info) {
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setExt_alarmTypeExt(true);
            queryModel.setShow12(true);
        }

        Integer page = HzhrTypeUtil.object2integer(query.get("_page"));
        Integer count = HzhrTypeUtil.object2integer(query.get("_count"));
        queryModel.setPage(page, count);

        return queryModel;
    }

}

